package com.saasitems.admin.service;

import com.saasitems.admin.dao.MediaResMapper;
import com.saasitems.admin.dao.RegisterMapper;
import com.saasitems.admin.model.MediaRes;
import com.saasitems.admin.model.Register;
import com.saasitems.admin.model.RegisterExample;
import com.saasitems.common.utils.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/4/11.
 */
@Service
@Transactional(readOnly = true)
public class RegisterService {

    @Autowired
    private RegisterMapper registerMapper;

    @Transactional(readOnly=false)
    public void saveInfo(String ip, Integer idvalue) {
        Register r = new Register();
        r.setIdvalue(idvalue);
        r.setIp(ip);
        r.setCreateTime(new Date());
        this.registerMapper.insert(r);
    }

    public Register getInfo(String ip) {
        RegisterExample ex = new RegisterExample();
        RegisterExample.Criteria c = ex.createCriteria();
        c.andIpEqualTo(ip);

        ex.setOrderByClause("id desc, create_time desc");
        List<Register> l = registerMapper.selectByExample(ex);
        if (l != null && !l.isEmpty()) {
            return l.get(0);
        }
        return null;
    }

}
